<?php

class noiseporn_scraper extends BlogScraper
{
    function __construct()
    {
        parent::__construct('noiseporn');
    }
    
    
    function getPostLinks()
    {
        $links = $this->xpath->query("//h1//a");
        return $links;    
    }
}

class noiseporn_post_scraper extends PostScraper
{
    function getTitle()
    {
        $text = $this->xpath->query("//h1//a")->item(0)->nodeValue;
        return $text;
    }
    
    function getLink()
    {
        $text = $this->xpath->query("//h1//a")->item(0)->getAttribute('href');
        return $text;
    }

    function getObjects()
    {
        $objects = $this->xpath->query("//div[@class='post']//object");
        $object_return = array();
        
        foreach ($objects as $object)
        {
            foreach ($object->getElementsByTagName('param') as $embed)
            {
                if ($embed->getAttribute('name') == "FlashVars") 
                {
                    $flashvars = $embed->getAttribute('value');
                    $parts = explode('&', $flashvars);
                    $vars = array();
                    
                    foreach ($parts as $part)
                    {
                        list($key, $val) = explode('=', $part);
                        $vars[$key] = $val;
                    }
                    
                    $object_return[] = $vars;
                    
                    continue;
                }
            }
        }

        return $object_return;
    } 
    
    function getObjectLinks()
    {
        $urls = array();
        
        foreach ($objects as $object)
        {
            $urls[] = str_replace(' ', '%20', urldecode($object['soundFile']));
        }
        
        return $urls;
    }
    
    function getDate()
    {
        $date = $this->xpath->query("//html//body//h1/a")->item(0)->getAttribute('href');
        $date_parts = explode("/",$date);
        $date = $date_parts[3].'-'.$date_parts[4].'-'.$date_parts[5];
        echo $date;
        return date('Y-m-d H:i:s', strtotime($date));

    }
    
    function prepareTrack($track)
    {
        $name_parts = explode('–', $track['name']);
        
        if (count($name_parts) == 2)
        {
            $track['artist'] = $this->removeQuotes(trim($name_parts[0]));
            $track['song'] = $this->removeQuotes(trim($name_parts[1]));
            $track['name'] = $track['artist'].'-'.$track['song'];
        }
        

        return $track;
    }    
}

?>